package com.dhh.vo;

import java.util.ArrayList;
import java.util.List;

public class FoodPlan {
	public static final String C_ID = "_id";
	public static final String C_DATE = "date";
	public static final String C_GRAIN = "grain";
	public static final String C_FRUIT = "fruit";
	public static final String C_VEGETABLE = "vegetable";
	public static final String C_PROTEINFOOD = "protein_food";
	public static final String C_DAIRY = "dairy";
	public static final String C_GOAL = "goal_id";
	public static final String C_ENERGY = "energy";
	
	private String id;
	private String date;
	private String grain;
	private String fruit;
	private String vegetable;
	private String proteinFood;
	private String dairy;
	private String goal;
	private String energy;

	private List<PlanItem> breakFast;
	private List<PlanItem> lunch;
	private List<PlanItem> dinner;
	private List<PlanItem> snack;	
	
	private Long cGrain;
	private Long cFruit;
	private Long cVegetable;
	private Long cDairy;
	private Long cProtein;
	
	public String getCurrentGrain() {
		return String.valueOf(cGrain);
	}

	public String getCurrentFruit() {
		return String.valueOf(cFruit);
	}

	public String getCurrentVegetable() {
		return String.valueOf(cVegetable);
	}

	public String getCurrentDairy() {
		return String.valueOf(cDairy);
	}

	public String getCurrentProteinFood() {
		return String.valueOf(cProtein);
	}

	public String getEnergy() {
		return energy;
	}

	public void setEnergy(String energy) {
		this.energy = energy;
	}

	
	public void initCurentCount(){
		List<PlanItem> items = new ArrayList<PlanItem>();
		items.addAll(breakFast);
		items.addAll(lunch);
		items.addAll(dinner);
		items.addAll(snack);
		
		for(PlanItem item : items){
			if(Food.FOOD_GROUP_GRAIN.equals(item.getFoodGroup())){
				cGrain += Long.parseLong(item.getQuatity());
			}else if(Food.FOOD_GROUP_FRUIT.equals(item.getFoodGroup())){
				cFruit += Long.parseLong(item.getQuatity());	
			}else if(Food.FOOD_GROUP_VEGETABLE.equals(item.getFoodGroup())){
				cVegetable += Long.parseLong(item.getQuatity());	
			}else if(Food.FOOD_GROUP_PROTEIN.equals(item.getFoodGroup())){
				cProtein += Long.parseLong(item.getQuatity());		
			}else if(Food.FOOD_GROUP_DAIRY.equals(item.getFoodGroup())){
				cDairy += Long.parseLong(item.getQuatity());
			}				
		}
	}
	
	public String getCurrentEnergy(){
		List<PlanItem> items = new ArrayList<PlanItem>();
		items.addAll(breakFast);
		items.addAll(lunch);
		items.addAll(dinner);
		items.addAll(snack);
		
		int count = 0;
		for(PlanItem item : items){
			if(item.getEnergy()!=null){
				count += Integer.parseInt(item.getEnergy());
			}
		}
		
		return String.valueOf(count);
	}
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public String getGrain() {
		return grain;
	}
	public String getGrainUnit() {
		return "oz";
	}
	public void setGrain(String grain) {
		this.grain = grain;
	}
	public String getFruit() {
		return fruit;
	}
	public String getFruitUnit() {
		String u = "cup";
		if(fruit!=null && fruit.trim().length()>0 && Double.parseDouble(fruit)>1){
			u += "s";
		}
		return u;
	}
	public void setFruit(String fruit) {
		this.fruit = fruit;
	}
	public String getVegetable() {
		return vegetable;
	}
	public String getVegetableUnit() {
		String u = "cup";
		if(vegetable!=null && vegetable.trim().length()>0 && Double.parseDouble(vegetable)>1){
			u += "s";
		}
		return u;
	}
	public void setVegetable(String vegetable) {
		this.vegetable = vegetable;
	}
	public String getProteinFood() {
		return proteinFood;
	}
	public String getProteinFoodUnit() {
		return "oz";
	}
	public void setProteinFood(String proteinFood) {
		this.proteinFood = proteinFood;
	}
	public String getDairy() {
		return dairy;
	}
	public String getDairyUnit() {
		String u = "cup";
		if(dairy!=null && dairy.trim().length()>0 && Double.parseDouble(dairy)>1){
			u += "s";
		}
		return u;
	}
	public void setDairy(String dairy) {
		this.dairy = dairy;
	}
	public List<PlanItem> getBreakFast() {
		return breakFast;
	}
	public void setBreakFast(List<PlanItem> breakFast) {
		this.breakFast = breakFast;
	}
	public List<PlanItem> getLunch() {
		return lunch;
	}
	public void setLunch(List<PlanItem> lunch) {
		this.lunch = lunch;
	}
	public List<PlanItem> getDinner() {
		return dinner;
	}
	public void setDinner(List<PlanItem> dinner) {
		this.dinner = dinner;
	}
	public List<PlanItem> getSnack() {
		return snack;
	}
	public void setSnack(List<PlanItem> snack) {
		this.snack = snack;
	}
	
	public String getGoal() {
		return goal;
	}

	public void setGoal(String goal) {
		this.goal = goal;
	}
	
	public static String[] getColumns(){
		return new String[]{C_ID,C_DATE,C_GRAIN,C_FRUIT,C_VEGETABLE,C_PROTEINFOOD,C_DAIRY,C_GOAL,C_ENERGY};
	}
}
